

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/2.jpg">
  <link rel="icon" type="image/png" href="/img/2.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="K">
  <meta name="keywords" content="">
  <title>docker-私有仓库Registry - K</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>かい</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-12-04 14:00" pubdate>
        2020年12月4日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      775 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      12
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">docker-私有仓库Registry</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="私有仓库"><a href="#私有仓库" class="headerlink" title="私有仓库"></a>私有仓库</h2><ul>
<li>本地的服务器仓库，用来存放局域网内的docker镜像</li>
<li>docker提供了私有仓库的镜像 registry:2 (1版本效率低)</li>
</ul>
<h2 id="私有仓库的搭建"><a href="#私有仓库的搭建" class="headerlink" title="私有仓库的搭建"></a>私有仓库的搭建</h2><table>
<thead>
<tr>
<th>192.168.100.211</th>
<th>私有仓库</th>
</tr>
</thead>
<tbody><tr>
<td>192.168.100.212</td>
<td>docker</td>
</tr>
</tbody></table>
<blockquote>
<p>两台主机都开启路由转发</p>
</blockquote>
<pre><code class="hljs ini"><span class="hljs-section">[root@localhost ~]</span><span class="hljs-comment"># echo &#x27;net.ipv4.ip_forward = 1 &#x27; &gt;&gt; /etc/sysctl.conf</span>
<span class="hljs-section">[root@localhost ~]</span><span class="hljs-comment"># sysctl -p</span>
<span class="hljs-attr">net.ipv4.ip_forward</span> = <span class="hljs-number">1</span></code></pre>
<blockquote>
<p>211主机下载私有仓库镜像</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker pull registry:<span class="hljs-number">2</span></code></pre>
<blockquote>
<p>创建私有仓库在本地的存放路径</p>
</blockquote>
<pre><code class="hljs autoit">[root<span class="hljs-symbol">@localhost</span> ~]<span class="hljs-meta"># mkdir -p /opt/data/registry</span></code></pre>
<blockquote>
<p>修改配置文件</p>
</blockquote>
<pre><code class="hljs gradle">[root@localhost ~]# vim <span class="hljs-regexp">/usr/</span>lib<span class="hljs-regexp">/systemd/</span>system/docker.service
# <span class="hljs-number">14</span>行
ExecStart=<span class="hljs-regexp">/usr/</span>bin<span class="hljs-regexp">/dockerd -H fd:/</span><span class="hljs-regexp">/ --containerd=/</span>run<span class="hljs-regexp">/containerd/</span>containerd.sock --insecure-registry <span class="hljs-number">192.168</span>.<span class="hljs-number">100.211</span>:<span class="hljs-number">5000</span> 
# --insecure-registry <span class="hljs-number">192.168</span>.<span class="hljs-number">100.211</span>:<span class="hljs-number">5000</span>  添加这个 让docker知道私有仓库的地址在哪</code></pre>
<blockquote>
<p>开启私有仓库容器</p>
</blockquote>
<pre><code class="hljs vala">[root@localhost ~]# docker run -itd --name registry --restart always -p <span class="hljs-number">5000</span>:<span class="hljs-number">5000</span> --volume /opt/data/registry/:/<span class="hljs-keyword">var</span>/lib/registry registry:<span class="hljs-number">2</span>
<span class="hljs-number">7</span>dd94807082943b81439ffce5589c747943892454f2595477a6e65da81902c9c

<span class="hljs-meta"># -p：指定端口，5000:5000表示在物理机开一个端口，在容器内开一个端口</span>
<span class="hljs-meta"># --restart always：无论容器遇到什么错误就会重启容器</span>
<span class="hljs-meta"># -v/--volume：本地目录映射到容器内的目录</span>
<span class="hljs-meta"># 5000：是registry的端口号</span>
<span class="hljs-meta"># /var/lib/registry：是registry仓库中存放镜像的目录</span></code></pre>
<blockquote>
<p>重启docker（因为修改了配置文件）</p>
</blockquote>
<pre><code class="hljs autoit">[root<span class="hljs-symbol">@localhost</span> ~]<span class="hljs-meta"># systemctl daemon-reload # 重新加载配置文件</span>
[root<span class="hljs-symbol">@localhost</span> ~]<span class="hljs-meta"># systemctl restart docker # 重启服务</span></code></pre>
<blockquote>
<p>211主机上传镜像</p>
</blockquote>
<pre><code class="hljs angelscript"># 使用tag 将镜像改名 （改名后的镜像会是一个新的镜像）
<span class="hljs-string">[root@localhost ~]</span># docker tag httpd:latest <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd
<span class="hljs-string">[root@localhost ~]</span># docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
<span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd   latest              <span class="hljs-number">417</span>af7dc28bc        <span class="hljs-number">2</span> months ago        <span class="hljs-number">138</span>MB
httpd                        latest              <span class="hljs-number">417</span>af7dc28bc        <span class="hljs-number">2</span> months ago        <span class="hljs-number">138</span>MB
busybox                      latest              <span class="hljs-number">6858809</span>bf669        <span class="hljs-number">2</span> months ago        <span class="hljs-number">1.23</span>MB
centos                       latest              <span class="hljs-number">7e6257</span>c9f8d8        <span class="hljs-number">3</span> months ago        <span class="hljs-number">203</span>MB
registry                     <span class="hljs-number">2</span>                   <span class="hljs-number">2</span>d4f4b5309b1        <span class="hljs-number">5</span> months ago        <span class="hljs-number">26.2</span>MB</code></pre>
<blockquote>
<p>将改完名后的镜像上传到私有仓库中</p>
</blockquote>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># docker push <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd
<span class="hljs-string">[root@localhost ~]</span># curl <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/v2/_catalog
&#123;<span class="hljs-string">&quot;repositories&quot;</span>:[<span class="hljs-string">&quot;httpd&quot;</span>]&#125;</code></pre>
<blockquote>
<p>212修改docker配置文件</p>
</blockquote>
<pre><code class="hljs awk">[root@localhost ~]<span class="hljs-comment"># vim /usr/lib/systemd/system/docker.service</span>
<span class="hljs-comment"># 14行</span>
ExecStart=<span class="hljs-regexp">/usr/</span>bin<span class="hljs-regexp">/dockerd -H fd:/</span><span class="hljs-regexp">/ --containerd=/</span>run<span class="hljs-regexp">/containerd/</span>containerd.sock --insecure-registry <span class="hljs-number">192.168</span>.<span class="hljs-number">100.211</span>:<span class="hljs-number">5000</span> 
<span class="hljs-comment"># --insecure-registry 192.168.100.211:5000  添加这个 让docker知道私有仓库的地址在哪</span>
<span class="hljs-comment"># ip是私有仓库的地址</span></code></pre>
<blockquote>
<p>下载私有仓库的镜像</p>
</blockquote>
<pre><code class="hljs angelscript"># 查看私有仓库的镜像
<span class="hljs-string">[root@localhost ~]</span># curl <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/v2/_catalog
&#123;<span class="hljs-string">&quot;repositories&quot;</span>:[<span class="hljs-string">&quot;httpd&quot;</span>]&#125;

# 下载镜像
<span class="hljs-string">[root@localhost ~]</span># docker pull <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd
Using <span class="hljs-keyword">default</span> tag: latest
latest: Pulling <span class="hljs-keyword">from</span> httpd
Digest: sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db
Status: Downloaded newer image <span class="hljs-keyword">for</span> <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd:latest
<span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd:latest
# 查看镜像
<span class="hljs-string">[root@localhost ~]</span># docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
<span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd   latest              <span class="hljs-number">417</span>af7dc28bc        <span class="hljs-number">2</span> months ago        <span class="hljs-number">138</span>MB
httpd                        latest              <span class="hljs-number">417</span>af7dc28bc        <span class="hljs-number">2</span> months ago        <span class="hljs-number">138</span>MB
busybox                      latest              <span class="hljs-number">6858809</span>bf669        <span class="hljs-number">2</span> months ago        <span class="hljs-number">1.23</span>MB
centos                       latest              <span class="hljs-number">7e6257</span>c9f8d8        <span class="hljs-number">3</span> months ago        <span class="hljs-number">203</span>MB
# 开启容器
<span class="hljs-string">[root@localhost ~]</span># docker run -itd --name httpd <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/httpd
<span class="hljs-number">196</span>c79a987094147eef856ccf1438fda7e79032fc2602dcd66458de5e4de2b6d
# 访问httpd服务
<span class="hljs-string">[root@localhost ~]</span># curl <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span>
&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;

# 上传centos镜像
<span class="hljs-string">[root@localhost ~]</span># docker tag centos:latest <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/centos
docker push <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/centos

# 查看私有仓库
<span class="hljs-string">[root@localhost ~]</span># curl <span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.211</span>:<span class="hljs-number">5000</span>/v2/_catalog
&#123;<span class="hljs-string">&quot;repositories&quot;</span>:[<span class="hljs-string">&quot;centos&quot;</span>,<span class="hljs-string">&quot;httpd&quot;</span>]&#125;
</code></pre>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/docker/">docker</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/docker/">docker</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章是以学习为目的，如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/12/04/docker%E5%AE%B9%E5%99%A8%E7%9A%84%E7%8A%B6%E6%80%81/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">docker容器的状态</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/12/03/docker%E6%A0%B8%E5%BF%83%E5%8E%9F%E7%90%86-docker%E9%95%9C%E5%83%8F%E5%88%86%E5%B1%82/">
                        <span class="hidden-mobile">docker核心原理-docker镜像分层</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://space.bilibili.com/39165374" target="_blank" rel="nofollow noopener"><span>LMK</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "docker-私有仓库Registry&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
